﻿using System.Linq;
using PersonaLibrary.PersonaliiReference;

namespace PersonaLibrary.ViewModel.JobViewModel
{
    internal class JobViewModel : ReferenceEditableItem<Job>
    {
        public JobViewModel()
        {
            EditableItem = new Job();
        }

        public JobViewModel(int id)
        {
        	EditableItem =
        		Context.CreateAndExecuteQuery<Job>(
					string.Format("Job?$filter=Id eq {0}&$expand=ConnectionJobEmplDep,ConnectionJobEmplDep/Employee,ConnectionJobEmplDep/Department/Organization&$select=*,ConnectionJobEmplDep/Employee/*,ConnectionJobEmplDep/Department/Organization/Name", id)).Single();
        }

        public override bool CanCommit()
        {
            return !(string.IsNullOrEmpty(EditableItem.Name));
        }
    }
}
